#!/usr/bin/perl
# Version 0.2.1

$testcase = "dd_mtu_set";

# 1 = PASS
# 2 = FAIL
# 3 = INCONCLUSIVE
$verdict = 3;

$dumpfile = "$testcase.dump";
$logfile = "$testcase.log";

if ($#ARGV ne 1) {
        print("Usage: $testcase.pl dump_file log_file");
        exit 1;
}

$dumpfile = $ARGV[0];
$logfile = $ARGV[1];

#------------------------------------------------------------------------------

@local_verdict = ( 3, 3 );

for ($i = 0; $i < 2; $i++) {
	# Open the dumpfile
	$success = 1;
	open(DUMPFILE, $dumpfile) or $success = 0;
	
	$initial = 1;
	if($success eq 1) {
		while(<DUMPFILE>) {
			if(/OSPFv2-dd/) {
				# only look at dd packets
				if ($_ =~ /mtu 1500/) {
					if($initial eq 1) {
						$initial = 0;
						$local_verdict[0] = 1;
					}
				} else {
					$local_verdict[0] = 2;
				}
			}
			
			# test for virual lnks must come here
		}
		
		close(DUMPFILE);
	}

}


# finally evaluate results and generate report
if ($local_verdict[0] eq 1) {
	print("MTU field is set to 1500 in all DD packets. Test PASSED.\n");
} elsif ($local_verdict[1] eq 2) {
	print("MTU field is not set correctly in some DD packets. Test FAILED.\n");
} else {
	print("Cannot determine MTU in DD packets. Test INCONCLUSIVE.\n");
}

if ($local_verdict[1] eq 1) {
	print("MTU on virtual link is set to 0. Test PASSED.\n");
} elsif ($local_verdict[2] eq 2) {
	print("MTU on virtual link is not set correctly in some DD packets. Test FAILED.\n");
} else {
	print("Virtual links are not supported yet. Test INCONCLUSIVE.\n");
}


$verdict = $local_verdict[0];
if ($local_verdict[1] ne $verdict) {
	if($local_verdict[1] eq 2) {
		$verdict = 2;
	} elsif ($local_verdict[1] eq 3) {
		if($verdict ne 2) {
			$verdict = 3;
		}
	}	
}

#------------------------------------------------------------------------------
print("### VERDICT for $testcase: ");

if ($verdict eq 1) { 
        print("PASS"); 
} elsif ($verdict eq 2) {
        print("FAIL");
} else {
        print("INCONCLUSIVE");
}

print(" ###\n");